<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>注册(3/3)</title>
    <link rel="stylesheet" href="../css/reset.css" />
    <link rel="stylesheet" href="../css/global.css" />
    <link rel="stylesheet" href="../css/regist3.css" />
    <script src="../lib/autoSize.js"></script>
    <script src="../lib/fastclick.js"></script>

    <script>
        if ('addEventListener' in document) {
            document.addEventListener('DOMContentLoaded', function () {
                FastClick.attach(document.body);
            }, false);
        }
    </script>
</head>

<body>
<header>
    <div class="left-btn">
        <img class="back" src="../images/header/back.png" alt="" onclick="history.go(-1)">
    </div>
    <h1 class="">注册（3/3）</h1>
    <div class="right-btn">
        <!-- 此处写右边按钮-->
    </div>
</header>

    <main>
        <div class="area_white">
            <div id="phone" class="form_control">
                <input class="input_control full_input" type="password" value="" placeholder="请输入6-15位密码">
            </div>
            <div id="verify" class="form_control">
                <input class="input_control full_input" type="password" value="" placeholder="请再次输入密码" name="">
            </div>
        </div>
        <div class="text-center" style="margin-top: 2.5rem">
            <button class="btn btn_primary">申请注册</button>
        </div>

        <div class="success">
            <div>
                <img src="../images/regist/success.png" alt="">
                <h1>申请已成功提交！</h1>
                <p>审核状态会以短信方式发送到您的手机</p>
                <button>确定</button>
            </div>
        </div>
    </main>

    <script src="../lib/jquery-3.2.1.min.js"></script>
    <script src="../lib/fastclick.js"></script>
    <script src="../lib/layer.js"></script>
    <script src="../js/common.js"></script>
    <script>
        $(function() {
            FastClick.attach(document.body);
        });

        //    点击注册
        $(".btn_primary").on("click", function () {
            if (!($("#phone input").val().length >= 6 && $("#phone input").val().length <= 15)) {
                layer.open({
                    content: '密码格式不正确(6-15位)！',
                    skin: 'msg',
                    time: 1
                });
            } else if ($("#phone input").val() != $("#verify input").val()) {
                layer.open({
                    content: '两次密码不一致！',
                    skin: 'msg',
                    time: 1
                });
            } else {
                toRegist($("#phone input").val());
            }
        })

        //      获取传来的参数
        function GetQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return (r[2]);
            return null;
        }

        var phoneNumber = GetQueryString("phoneNumber");
        var realName = decodeURI(GetQueryString("realName"));
        var idcard = GetQueryString("idcard");
        var areaId = GetQueryString("areaId");
        var sex = GetQueryString("sex");
        var areaName = decodeURI(GetQueryString("areaName"));
        var productPic = localStorage.getItem("img1") + "∮" + localStorage.getItem("img2");

        //    注册方法
        var flag = false;

        function toRegist(pswd) {
            if (flag) {
                layer.open({
                    content: '请勿重复提交！',
                    skin: 'msg',
                    time: 1
                });
                return;
            } else {
                layer.open({
                    content: '正在提交，请稍后！',
                    skin: 'msg',
                    time: 1
                });
            }
            flag = true;
            $.ajax({
                //            url: CONFIG.GENERAL_IPS[0].phoneRegister+"&phoneNumber="+phoneNumber+"&ugroupId="+CONFIG.ugroupId+"&businessId="+CONFIG.businessId+"&password="+pswd+"&realName="+realName+
                //                "&idcard+"+idcard+"&ugroupName="+CONFIG.ugroupName+"&productPic="+productPic+"&areaId="+areaId+"&areaName="+areaName,
                url: CONFIG.CONFIG_IP+CONFIG.GENERAL_IPS[0].phoneAndIdcardImgRegister2,
                type: "POST",
                dataType: "json",
                data: {
                    phoneNumber: phoneNumber,
                    ugroupId: CONFIG.ugroupId,
                    businessId: CONFIG.businessId,
                    password: pswd,
                    realName: realName,
                    idcard: idcard,
                    sex: sex,
                    ugroupName: CONFIG.ugroupName,
                    productPic: productPic,
                    areaId: areaId,
                    areaName: areaName
                },
                success: function (data) {
                    if (data.status == "1") {
                        $(".success").show();
                    } else if (data.msg.indexOf("已在")) {
                        layer.open({
                            content: '该手机号已注册过,请直接登录...',
                            skin: 'msg',
                            time: 1
                        });
                        flag = false;
                        setTimeout(function () {
                            window.location = "login.html";
                        }, 1000);
                    }
                },
                error: function () {}
            })
        }
        
        $(".success button").on("click", function () {
            window.location = "login.html";
        })
    </script>
</body>

</html>